module.exports = {
  formatBook(data, book, bid) {
    data.book = {};
    data.book.title = book.title;
    data.is_verify = book.is_verify;
    data.has_verify_code = book.has_verify_code;
    data.btn_txt = "验证";
    data.book_type_txt = "图书";
    data.has_ex = book.has_ex;
    if(data.has_verify_code == 2){
      data.btn_txt = "兑换"
    }
    if(book.book_type == 3){
      data.book_type_txt = "课程"
    }
    // data.is_subscribe = book.is_subscribe;
    data.book.years = "";
    if (book.version_years != 0) {
      data.book.years = book.version_years + "版";
    }
    data.book.subject_name = book.subject_name;
    data.book.grade_name = book.grade_name;
    data.book.img_url = book.img_url;
    data.book.happy_buy_info = book.happy_buy_info;
    // data.book.wx_code = code;
    data.book.bid = bid;
    data.book.detail = "增值资料：";
    var arr = [];
    if(book.has_online_test == 1){
      arr.push("在线测评");
    }
    if(book.has_online_test == 2){
      arr.push("智能辅导");
    }
    if(book.online_tp != ""){
      arr.push("在线统评");
    }
    data.questionnaire_id = book.questionnaire_id;
    if(book.questionnaire_id > 0){
      arr.push("有奖反馈");
    }
    if (book.book_resource_base && book.book_resource_base.length > 0) {
      book.book_resource_base.forEach((e, i) => {
        arr.push(e.type_name);
      });
    }
    if(arr.length == 0){
      if(book.has_ex == 1){
        if(book.ex_tooltip == ""){
          data.book.detail = "增值资料正在准备中！";
        }else{
          data.book.detail = book.ex_tooltip;
        }
      }else{
        data.book.detail = "该图书无增值资料！";
      }
    }else{
      data.book.detail += arr.join("、");
    }
    return data;
    },
    formatBook2(data, book, bid) {
      data.book = {};
      data.book.title = book.title;
      data.is_verify = book.is_verify;
      data.has_verify_code = book.has_verify_code;
      data.is_subscribe = book.is_subscribe;
      data.book.years = "";
      if (book.version_years != 0) {
          data.book.years = book.version_years + "版";
      }
      data.book.subject_nam = "";
      if (book.subject_data && book.subject_data.length > 0) {
          data.book.subject_name = book.subject_data[0].name;
      }
      data.book.grade_name = "";
      if (book.grade_data && book.grade_data.length > 0) {
          data.book.grade_name = book.grade_data[0].name;
      }
      data.book.img_url = book.img_url;
      // data.book.wx_code = code;
      data.book.bid = bid;
      if (book.book_resource_base && book.book_resource_base.length > 0) {
          data.book.detail = "增值资料：";
          book.book_resource_base.forEach((e, i) => {
              if (i == 0) {
                  data.book.detail += e.type_name;
              } else {
                  data.book.detail += "、" + e.type_name;
              }
          });
      } else {
          data.book.detail = "增值资料正在准备中！"
      }
      return data;
     },
    getWxLoginUrl(){
        var h ={}
        h.BASE = "snsapi_base";
        h.USER_INFO = "snsapi_userinfo";
        const APPID = 'wx8e00a187a937157e';
        h.getWxLoginUrl = function(app_id,redirect_uri,scope,state) {
            let url = 'https://open.weixin.qq.com/connect/oauth2/authorize?'+
            'appid=' + app_id +
            '&redirect_uri=' + encodeURIComponent(redirect_uri) +
            '&response_type=code&scope=' + scope +
            '&state=' + state +
            '#wechat_redirect';
            return url;
        }
    }
};